import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '@/views/Login/Login.vue'
import { useMenusStore } from '@/stores'
import DataPanel from '@/views/DataPanel/DataPanel.vue'
import OrderManagement from '@/views/OrderManagement/OrderManagement.vue'
import InformationManagement from '@/views/InformationManagement/InformationManagement.vue'
import FileUpload from '@/views/FileUpload/FileUpload.vue'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'data-panel',
      component: DataPanel
    },
    {
      path: '/info',
      name: 'information-management',
      component: InformationManagement
    },
    {
      path: '/order',
      name: 'order-management',
      component: OrderManagement
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/upload',
      name: 'upload',
      component: FileUpload
    }
  ]
})
const store = useMenusStore()
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next()
  } else {
    if (store.isShow) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
